package com.liujit.bms.admin.controller;

import com.liujit.bms.admin.domain.params.BlogArticleParams;
import com.liujit.bms.admin.domain.query.BlogArticleQuery;
import com.liujit.bms.admin.domain.result.BlogArticleResult;
import com.liujit.bms.admin.service.BlogArticleService;
import com.liujit.common.domain.params.BaseParams;
import com.liujit.common.domain.result.PageBean;
import com.liujit.validator.group.AddGroup;
import com.liujit.validator.group.ModifyGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 博客文章管理接口
 * @Author liujun
 * @Date 2021-07-03 14:54:49
 */
@RequiredArgsConstructor
@Api(tags = "博客文章管理接口")
@RestController
@RequestMapping("/blog/article")
public class BlogArticleController {

    private final BlogArticleService blogArticleService;

    @ApiOperation(value = "分页查询", notes = "根据博客文章分页查询条件，分页查询博客文章列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "博客文章分页查询条件", dataType = "BlogArticleQuery", dataTypeClass = BlogArticleQuery.class, paramType = "query") })
    @GetMapping("/getPage")
    public PageBean<BlogArticleResult> getPage(BlogArticleQuery query) {
        return blogArticleService.getPage(query);
    }

    @ApiOperation(value = "添加", notes = "根据博客文章添加请求参数，添加博客文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客文章添加请求参数", dataType = "BlogArticleParams", dataTypeClass = BlogArticleParams.class, paramType = "body") })
    @PostMapping("add")
    public Boolean add(@RequestBody @Validated(AddGroup.class) BlogArticleParams params) {
        return blogArticleService.save(params);
    }

    @ApiOperation(value = "修改", notes = "根据博客文章修改请求参数，修改博客文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客文章修改请求参数", dataType = "BlogArticleParams", dataTypeClass = BlogArticleParams.class, paramType = "body") })
    @PostMapping("/modify")
    public Boolean modify(@RequestBody @Validated(ModifyGroup.class) BlogArticleParams params) {
        return blogArticleService.save(params);
    }

    @ApiOperation(value = "查询", notes = "根据博客文章id，查询博客文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "博客文章id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/get")
    public BlogArticleResult get(Long id) {
        return blogArticleService.get(id);
    }

    @ApiOperation(value = "查询详情", notes = "根据博客文章id，查询博客文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "博客文章id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/getDetail")
    public BlogArticleResult getDetail(Long id) {
        return blogArticleService.getDetail(id);
    }

    @ApiOperation(value = "删除", notes = "根据博客文章删除请求参数，删除博客文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客文章删除请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/del")
    public Boolean del(@RequestBody BaseParams params) {
        return blogArticleService.del(params);
    }

    @ApiOperation(value = "公开", notes = "根据博客文章公开请求参数，公开博客文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客文章公开请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/open")
    public Boolean open(@RequestBody BaseParams params) {
        return blogArticleService.open(params);
    }

    @ApiOperation(value = "取消公开", notes = "根据博客文章取消公开请求参数，取消公开博客文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客文章取消公开请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/cancelOpen")
    public Boolean cancelOpen(@RequestBody BaseParams params) {
        return blogArticleService.cancelOpen(params);
    }

    @ApiOperation(value = "置顶", notes = "根据博客文章置顶请求参数，置顶博客文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客文章置顶请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/top")
    public Boolean top(@RequestBody BaseParams params) {
        return blogArticleService.top(params);
    }

    @ApiOperation(value = "取消置顶", notes = "根据博客文章取消置顶请求参数，取消置顶博客文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客文章取消置顶请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/cancelTop")
    public Boolean cancelTop(@RequestBody BaseParams params) {
        return blogArticleService.cancelTop(params);
    }
}
